import 'package:flutter/material.dart';
import 'package:kk/model/common_model.dart';
import 'package:kk/widget/webview.dart';

class LocalNav extends StatelessWidget {
  final List<CommonModel> localNavList;

  const LocalNav({Key? key, required this.localNavList}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(6))),
      child: Padding(
        padding: EdgeInsets.all(7),
        child: _items(context),
      ),
    );
  }

  _items(BuildContext context) {
    // ignore: unnecessary_null_comparison
    if (localNavList == null) return null;
    List<Widget> items = [];
    localNavList.forEach((element) {
      items.add(_item(context, element));
    });
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: items,
    );
  }

  Widget _item(BuildContext context, CommonModel element) {
    return GestureDetector(
      onTap: () {
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => WebView(
                      url: element.url,
                      title: element.title,
                      statusBarColor: element.statusBarColor,
                      hideAppBar: element.hideAppBar,
                    )));
      },
      child: Column(
        children: [
          Image.network(
            element.icon,
            width: 32,
            height: 32,
          ),
          Padding(
            padding: EdgeInsets.only(top: 3),
            child: Text(
              element.title,
              style: TextStyle(fontSize: 12),
            ),
          ),
        ],
      ),
    );
  }
}
